package jjn.daily;

/**
 * @author Jjn
 * @since 2023/7/17 19:09
 */
public class LeetCode415 {
    public String addStrings(String num1, String num2) {
        int i = num1.length() - 1, j = num2.length() - 1;
        int carry = 0;
        StringBuilder res = new StringBuilder();
        while (i >= 0 || j >= 0) {
            int first = 0, second = 0;
            if (i >= 0) {
                first = num1.charAt(i) - '0';
            }
            if (j >= 0) {
                second = num2.charAt(j) - '0';
            }
            int sum = first + second + carry;
            carry = sum / 10;
            sum = sum % 10;
            res.append(sum);
            i--;
            j--;
        }
        if (carry > 0) {
            res.append(carry);
        }
        return res.reverse().toString();
    }
    
    public static void main(String[] args) {
        System.out.println("new LeetCode415().addStrings(\"11\", \"123\") = " + new LeetCode415().addStrings("99", "99999"));
    }
}
